namespace ghost {
	/**技能按钮，此游戏没用这个*/
	export class SkillBtn extends GYSprite{
		public group:GYSprite;
		public back:GYSprite;
		public icon:GYSprite;
		public coolLab:GYText;		
		private _player:GameRole;
		private _skillRet:SkillInfoRet;
		private _isCool:boolean;
		private _curTween:Laya.Tween;
		private _isDown:boolean;
		private _touchId:number;
		public skillBoard:SkillBoard;
		public constructor(skillboard:SkillBoard) {
			super();
			let s= this;
			s.skillBoard = skillboard;
			s.group = new GYSprite;
			s.addChild(s.group);
			s.back = SkinManager.createImage(s.group,0,0,null);//Conf.skillAlias + "bg_01.png"
			s.back.left = s.back.right = s.back.top = s.back.bottom = 0;		
			s.icon = SkinManager.createImage(s.group,0,0,null,null);
			s.icon.left = s.icon.right = s.icon.top = s.icon.bottom = 5;
			s.coolLab = SkinManager.createText(s.group, 0,0,"",0xffffff,50,"center",100,50);
			s.coolLab.left = s.coolLab.right = 0;
			s.coolLab.verticalCenter = 0;			
			s.coolLab.visible = false;
			s._touchId = NaN;
			s.mouseEnabled = true;
			// s.addEventListener(egret.TouchEvent.TOUCH_TAP, s.tap, s);
			s.on(Laya.Event.MOUSE_DOWN, s, s.tapBegin);
			s.on(Laya.Event.MOUSE_UP, s, s.tapEnd);			
		}
		public get width():number
		{
			return Laya.superGet(SkillBtn, this, "width");			
		}
		public get height():number
		{
			return Laya.superGet(SkillBtn, this, "height");			
		}
		public set width(val:number)
		{
			let s= this;			
			Laya.superSet(SkillBtn, this, "width", val);
			s.group.width = val;
			s.group.x = -(val>>1);
		}
		public set height(val:number)
		{
			let s= this;
			Laya.superSet(SkillBtn,s,"height",val);			
			s.group.height = val;
			s.group.y = -(val>>1);
		}
		public tapBegin(e:Laya.Event=null):void
		{
			let s =this;
			
			if(e)
			{
				// console.log("start",e.touchPointID,s._touchId);
				if(s._touchId == s._touchId && e.touchId != s._touchId)return;
				s._touchId = e.touchId;				
			}										
			let scale:number;
			scale = 0.8;			
			Laya.Tween.to(s, {scaleX:scale,scaleY:scale},100,Laya.Ease.linearNone,null,0,true,true)			
			// GYLite.GYSprite.addStageDown(s,s.outsideUp,s,false,s._touchId);
			s._isDown = true;
			// CircleLight.show(<GYSprite>s.parent,s.x,s.y,0,s.width,s.height);		
		}
		public tapEnd(e:Laya.Event=null):void
		{
			let s= this;
			if(e)
			{				
				// console.log("end",e.touchPointID,s._touchId);
				if(e.touchId != s._touchId)return;					
			}
			s._touchId = NaN;				
			Laya.Tween.to(s,{scaleX:1,scaleY:1},100,Laya.Ease.linearNone,null,0,true,true);
			if(e)			
				s.excSkill();
			s._isDown = false;	
			// CircleLight.show(<GYSprite>s.parent,s.x,s.y,0,s.width,s.height);		
		}
		// private outsideUp(e:GYLite.GYTouchEvent):void
		// {
		// 	let s= this;
		// 	// console.log("outsideUp",e.touchPointID,s._touchId);
		// 	s._isDown = false;
		// 	s.tapEnd(e);			
		// }
		// private tap(e:egret.TouchEvent):void
		// {
			
		// }
		public excSkill():void
		{
			let s= this;
			if(s._isCool)return;			
			if(s._skillRet.SkillID == 99999)
			{
				//切换技能
				s.skillBoard.switchSkill((s.skillBoard.round+1)%2);
				return;
			}			
			s._player.setOperSts(s._skillRet.SkillID);
		}
		public setData(player:GameRole,val:SkillInfoRet):void
		{
			let s = this;
			s._skillRet = val;
			s._player = player;
			
			// s.back.source = Main.instance.getRes(Conf.skillAlias + "bg_01.png");
			// if(s._skillRet)
			// 	s.icon.source = Main.instance.hasRes(Conf.skillAlias + s._skillRet.SkillID + ".png")?Main.instance.getRes(Conf.skillAlias + s._skillRet.SkillID + ".png"):Main.instance.getRes(Conf.skillAlias+StsType.ATTACK + ".png");
			s.icon.visible = true;
						
			s._isCool = true;			
			s.coolLab.visible = false;
			if(s._skillRet)
			{				
				CommonUtil.addStageLoop(s.coolDown, s);
				s.coolDown(Date.now(), true);
			}				
			else
				CommonUtil.delStageLoop(s.coolDown, s);
				
		}
		public coolDown(t:number,reset:boolean=false):void
		{
			let s= this;			
			let skillID:number,leftTime:number,st:number;			
			let cool:boolean;
			let lt:number;
			skillID = s._skillRet.SkillID;
			leftTime = s._player.isSkillCoolEnd(skillID);			
			cool = leftTime > 0;
			if(cool)
			{				
				if(leftTime < 1000)
					s.coolLab.text = ((leftTime / 100|0) / 10) + "";					
				else
					s.coolLab.text = Math.ceil(leftTime/1000) + "";
			}
			if(s._isCool == cool && !reset)				
				return;
			s._isCool = cool;
			if(cool)
			{
				s.coolLab.visible = true;
				s.icon.alpha = 0.5;				
			}
			else
			{
				s.coolLab.visible = false;
				s.icon.alpha = 1;				
			}
		}
		public get skillID():number
		{
			return this._skillRet?this._skillRet.SkillID:-1;
		}
	}
}